Typical HAL AES use cases for migration ¶
This section provides typical HAL AES use cases to help migrate from HAL1 CRYP to HAL2 AES.
Use case: encryption/decryption in polling mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Encryption */
HAL_CRYP_Encrypt(&hcryp, Plaintext, PLAINTEXT_SIZE,
EncryptedText, TIMEOUT_VALUE);
/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Decryption */
HAL_CRYP_Decrypt(&hcryp,Ciphertext , PLAINTEXT_SIZE,
DecryptedText, TIMEOUT_VALUE);
/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
|
/* Encryption */
HAL_AES_Encrypt(&haes, Plaintext, PLAINTEXT_SIZE ,
EncryptedText, TIMEOUT_VALUE);
/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Decryption */
HAL_AES_Decrypt(&haes, Ciphertext, PLAINTEXT_SIZE ,
DecryptedText, TIMEOUT_VALUE);
/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
|
Key changes ¶
Encryption and decryption APIs are renamed from
HAL_CRYP_*toHAL_AES_*.Authentication tag generation APIs are renamed from
HAL_CRYPEx_AES*toHAL_AES_*for GCM and CCM algorithms.
Use case: encryption/decryption in interrupt mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Encryption */
HAL_CRYP_Encrypt_IT(&hcryp, Plaintext, PLAINTEXT_SIZE,
EncryptedText);
/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Decryption */
HAL_CRYP_Decrypt_IT(&hcryp,Ciphertext , PLAINTEXT_SIZE,
DecryptedText);
/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
|
/* Encryption */
HAL_AES_Encrypt_IT(&haes, Plaintext, PLAINTEXT_SIZE,
EncryptedText);
/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Decryption */
HAL_AES_Decrypt_IT(&haes, Ciphertext, PLAINTEXT_SIZE,
DecryptedText);
/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
|
Key changes ¶
Interrupt-mode APIs are renamed from
HAL_CRYP_*_ITtoHAL_AES_*_IT.Tag generation APIs are renamed to
HAL_AES_GCM_GenerateAuthTAG()andHAL_AES_CCM_GenerateAuthTAG().
Related examples in HAL2 ¶
|
Example name |
Brief |
|---|---|
|
example_hal_cryp_cipher_aes_cbc_it |
How to use the CRYP peripheral to encrypt/decrypt data (plaintext/ciphertext) in interrupt mode using AES CBC. |
Use case: encryption/decryption in DMA mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Encryption */
HAL_CRYP_Encrypt_DMA(&hcryp, Plaintext, PLAINTEXT_SIZE,
EncryptedText);
/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Decryption */
HAL_CRYP_Decrypt_DMA(&hcryp,Ciphertext , PLAINTEXT_SIZE,
DecryptedText);
/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
TIMEOUT_VALUE);
|
/* Encryption */
HAL_AES_Encrypt_DMA(&haes, Plaintext, PLAINTEXT_SIZE ,
EncryptedText);
/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Decryption */
HAL_AES_Decrypt_DMA(&haes, Ciphertext, PLAINTEXT_SIZE ,
DecryptedText);
/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
TIMEOUT_VALUE);
|
Key changes ¶
DMA-mode APIs are renamed from
HAL_CRYP_*_DMAtoHAL_AES_*_DMA.Tag generation APIs are renamed from
HAL_CRYPEx_AES*toHAL_AES_*for GCM and CCM algorithms.
Related examples in HAL2 ¶
|
Example name |
Brief |
|---|---|
|
example_hal_cryp_cipher_aes_cbc_dma |
How to use the CRYP peripheral to encrypt/decrypt data (plaintext/ciphertext) using the AES CBC algorithm in DMA mode with swapping. |
Use case: suspend/resume mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
||||||||
|---|---|---|---|---|---|---|---|---|---|
|
|
Key changes ¶
HAL2 provides explicit suspend and context management APIs:
HAL_AES_RequestSuspend(),HAL_AES_SaveContext(), andHAL_AES_RestoreContext().HAL2 splits configuration steps into dedicated functions (for example,
HAL_AES_ECB_SetConfig()andHAL_AES_SetNormalKey()).







